package com.zqq.goods.service.impl

import com.zqq.baselibrary.ext.convert
import com.zqq.baselibrary.ext.convertBoolean
import com.zqq.goods.service.CartService
import com.zqq.goods.service.bean.CartGoods
import com.zqq.goods.service.repository.CartRepository
import rx.Observable
import javax.inject.Inject

/**
 * 购物车 业务层实现类
 * wc
 * @author zqq on 2018/8/5.
 */
class CartServiceImpl @Inject constructor() : CartService {

    @Inject
    lateinit var repository: CartRepository

    /*-1.获取购物车列表-*/
    override fun getCartList(): Observable<MutableList<CartGoods>?> {
        return repository.getCartList()
                .convert()
    }


    /* 加入购物车 */
    override fun addCart(goodsId: Int, goodsDesc: String, goodsIcon: String, goodsPrice: Long, goodsCount: Int, goodsSku: String): Observable<Int> {
        return repository.addCart(goodsId, goodsDesc, goodsIcon, goodsPrice, goodsCount, goodsSku)
                .convert()
    }

    /* 加入购物车(Map) */
    override fun addCart(map: Map<String, Any>): Observable<Int> {
        return repository.addCart(map)
                .convert()
    }


    /*删除购物车商品*/
    override fun deleteCartList(list: List<Int>): Observable<Boolean> {
        return repository.deleteCartList(list)
                .convertBoolean()
    }

    /**提交购物车商品*/
    override fun submitCart(list: MutableList<CartGoods>, totalPrice: Long): Observable<Int> {
        return repository.submitCart(list, totalPrice)
                .convert()
    }

}